<?php
/**
 * SambleSvc
 *
 * Samble main services class which contains basic functions for registry transaction.
 *
 * @author Lim Afriyadi
 * @version pre-alpha
 * @package Samble
 * @subpackage core
 * @license GNU/GPL
 */
abstract class SambleService
{

    /**
     * Array of registration entries object instances.
     * @var array
     */
    var $a_Instances = array();
    /**
     * Array of registration entries object class names.
     * @var array
     */
    var $a_Classes = array();
    /**
     * The class instance.
     * @var object
     */
    static $o_Instance;
    /**
     * Get defined object's instance.
     * @final
     * @param string $s_Class_Name
     * @return object
     */
    public static final function getObject( $s_Class_Name )
    {
        return self::$o_Instance->a_Instances[ $s_Class_Name ];
    }
    /**
     * Get defined object's class name.
     * @final
     * @param object $o_Object
     * @return string
     */
    public static final function classname( $o_Object )
    {
        return array_search( $o_Object, self::$o_Instance->a_Instances );
    }
    /**
     * Register defined object to SambleService instance.
     * @final
     * @param object $o_Object
     */
    public static final function register( $o_Object )
    {
        $s_Class_Name = get_class( $o_Object );
        self::$o_Instance->a_Classes[ $s_Class_Name ] = $s_Class_Name;
        self::$o_Instance->a_Instances[ $s_Class_Name ] = $o_Object;
    }
    /**
     * Unregister defined object from SambleService instance.
     * @final
     * @param object $o_Object
     */
    public static final function unregister( $o_Object )
    {
        $s_Key = array_search( self::$o_Instance->classname( $o_Object ), self::$o_Instance->a_Instances );
        if( $s_Key )
        {
            unset( self::$o_Instance->a_Instances[ $s_Key ] );
            unset( self::$o_Instance->a_Classes[ $s_Key ] );
        }
        self::$o_Instance->a_Instances = array_values( self::$o_Instance->a_Instances );
        self::$o_Instance->a_Classes = array_values( self::$o_Instance->a_Classes );
    }
    /**
     * Clear registration entries from SambleService instance.
     * @final
     */
    public static final function clear()
    {
        $this->a_Instances = array();
        $this->a_Instances['system'] = new Samble();
    }
    /**
     * Dump SambleService registration entries.
     * @final
     */
    public static final function dumpReg()
    {
        $a_Instances = self::$o_Instance->a_Instances;
        $i = 0;
        foreach(  $a_Instances as $o_Instance=>$o_Object )
        {
            $s_Name = self::$o_Instance->classname( $o_Object );
            echo "Instance( ".$i." ):<br/>";
            for( $j=0 ; $i < 20 ; $i++ )
            {
                echo '&nbsp;';
            }
            echo "class( " . $s_Name . " )<br/>";
            $i++;
        }
    }
}
?>